package cn.metafoo.common.exception;

import cn.metafoo.common.entity.ErrorCode;
import cn.metafoo.common.exception.enums.GlobalErrorCodeConstants;
import lombok.*;

/**
 * 服务器异常 Exception
 *
 * @Author: fatto
 * @create: 2023/3/23 14:22
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class ServerException extends RuntimeException {
    /**
     * 全局错误码
     *
     * @see GlobalErrorCodeConstants
     */
    @Getter
    private Integer code;
    /**
     * 错误提示
     */
    @Getter
    private String message;

    public ServerException(ErrorCode errorCode) {
        this.code = errorCode.getCode();
        this.message = errorCode.getMsg();
    }

    public ServerException setCode(Integer code) {
        this.code = code;
        return this;
    }

    public ServerException setMessage(String message) {
        this.message = message;
        return this;
    }
}
